import store from '@/store'
import axios from 'axios'
// import { Message } from 'element-ui'

const request = axios.create({
  baseURL: '/api',
  timeout: 5000
})

// 请求拦截器
request.interceptors.request.use(config => {
  if (store.getters.token) {
    config.headers.Authorization = `${store.getters.token}`
  }

  return config
}, error => {
  return Promise.reject(error)
})

// 响应拦截器
// request.interceptors.response.use(response => {
//   const { msg, success } = response.data
//   if (success) {
//     return response.data
//   } else {
//     Message.error(msg)
//     return Promise.reject(new Error(msg))
//   }
//   console.log(response)
//   return response
// }, error => {
//   return Promise.reject(error)
// })

export default request
